<template>
  <div>
    <el-tree
      :data="menu"
      :props="defaultProps"
      :expand-on-click-node="false"
      node-key="catId"
      ref="tree"
      @node-click="nodeClick"
    >
    </el-tree>
  </div>
</template>
<script>
export default {
  name: "",
  components: {},
  props: {},
  data() {
    return {
      menu: [],
      expandedKeys: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
    };
  },
  watch: {}, //监控data中的数据变化
  computed: {}, //计算属性 类似于data概念
  methods: {
    getMenus() {
      this.$http({
        url: this.$http.adornUrl("/product/category/list/tree"),
        method: "get",
      }).then(({ data }) => {
        //  console.log(data.data);
        this.menu = data.data;
      });
    },
    nodeClick(data,node,component){
      //向父组件发送事件
      this.$emit("tree-node-click",data,node,component);
    }
  }, //生命周期-创建完成（可以访问当前this实例）
  created() {
      this.getMenus();
  }, //生命周期-挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style scoped>
</style>